# -*- coding: utf-8 -*-
import threading
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

from engine import Engine
import settings

class Controller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        #是否更新
        #False表示下载url_queue的链接,True表示更新,
        self.run_list=[False,True]
        self.run_sqe=0
        self.engine_is_running=False
        
    def run(self):
        '''循环运行'''
        self.is_running=True
        #设置运行类型
        self.is_update=self.run_list[self.run_sqe]
        settings.S_is_update=self.is_update

        self.eng=Engine(settings.S_target_website)
        self.eng.start()
        
        self.run_sqe+=1
        if self.run_sqe>=len(self.run_list):
            self.run_sqe=0
            
        self.engine_is_running=True
        self.eng.join()
        if self.is_running:
            self.run()
        
    def stop(self):
        self.eng.is_running=False
        self.is_running=False
        









